package com.qf.service.impl;

import com.qf.entity.*;
import com.qf.entity.custom.UserEvaShopCustom;
import com.qf.entity.custom.UserToCouponCou;
import com.qf.mapper.*;
import com.qf.service.UserModuleService;
import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.security.auth.kerberos.KerberosTicket;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author tanchangming
 * @Date 2020.7.22
 */


@Service
public class UserModuleServiceImpl implements UserModuleService {


    @Autowired
    private UserModule userModule;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private UserEvaluationMapper userEvaluationMapper;

    @Override
    public List<UserEvaShopCustom> getUserEvaShopCustom() {
        List<UserEvaShopCustom> userEvaShopCustoms = new ArrayList<>();
        List<Integer> list = userModule.selectUserId();
        for (int i = 0; i < list.size(); i++) {

            UserEvaShopCustom userEvaShopCustom = userModule.selectUserEvaShop(i+1);
            if (userEvaShopCustom != null) {
                // System.out.println(userEvaShopCustom);
                userEvaShopCustoms.add(userEvaShopCustom);
            }
        }

            return userEvaShopCustoms;


    }

    @Override
    public boolean deleteUser(int id){
        User user = new User();
        user.setUserId(id);

         int i = userMapper.updateByPrimaryKeySelective(user);
         if (i != 0){
             return true;
         }
         else {
             return false;
         }

    }

    @Override
    public boolean deleteShop(int id){
       Shop shop = new Shop();

        shop.setShopId(id);
        int i = shopMapper.updateByPrimaryKeySelective(shop);
        if (i != 0){
            return true;
        }
        else {
            return false;
        }

    }

    @Override
    public boolean deleteProduct(int id){
        Product product = new Product();
        product.setProductId(id);

        int i = productMapper.updateByPrimaryKeySelective(product);
        if (i != 0){
            return true;
        }
        else {
            return false;
        }
    }

    @Override
    public boolean deleteEva(int id){
        UserEvaluation userEvaluation = new UserEvaluation();
        System.out.println(id);
        userEvaluation.setEvaluationId(id);

        int i = userEvaluationMapper.updateByPrimaryKeySelective(userEvaluation);

        if (i != 0){
            return true;
        }
        else {
            return false;
        }
    }


}
